﻿@{
    ViewBag.Title = "收货地址";
    Layout = "~/Views/Shared/_LayoutFore.cshtml";
}

@section script{
    <script type="text/javascript">
        ; (function (window, undefined, $) {
            $(document).ready(function () {
                var gridopt = {
                    url: options.listUrl,
                    colModel: [
                        { display: '默认状态', name: 'IsDefault', width: "5%", sortable: true, hide: true, align: 'left' },
                        { display: '编号', name: 'Id', width: "5%", sortable: true, hide: true, align: 'left', iskey: true },
                        { display: '会员ID', name: 'MemberId', width: "5%", sortable: true, hide: true, align: 'left', iskey: true },
                        { display: '收货人姓名', name: 'Name', width: "5%", sortable: true, hide: false, align: 'left' },
                        { display: '手机号码', name: 'Tel', width: "10%", sortable: false, align: 'left' },
                        { display: '收货地址', name: 'Address', width: "8%", sortable: false, align: 'left' },
                        { display: '添加时间', name: 'Addtime', width: "14%", sortable: false, hide: true, align: 'center' },
                        { display: '操作', name: 'Id', width: "14%", sortable: false, align: 'center', process: processOp },
                    ],
                    sortname: "Id",
                    sortorder: "DESC",
                    title: false,
                    rp: 14,
                    usepager: true,
                    showcheckbox: false
                };
                var xjgrid = new xjGrid("gridlist", gridopt);
                function processOp(value, cell) {
                    var ops = [];

                    if (cell[0] == 1) {
                        ops.push("&nbsp;<lable title='取消默认地址'  <i style='color:#F00'></i>默认地址</lable>");
                    } else {
                        ops.push("&nbsp;<a title='设为默认地址' href='javascript:;'  onclick=\"util.SetDefault('", value, "','", cell[2], "')\"><i class='fa fa-edit' ></i>设为默认地址</a>");
                    }

                    ops.push("&nbsp;<a title='编辑' href='javascript:;'  onclick=\"util.Edit('", value, "')\"><i class='fa fa-edit' ></i>编辑</a>");
                    ops.push("&nbsp;&nbsp;<a title='删除' class='abtn' href='javascript:;'  onclick=\"util.Delete('", value, "','", cell[1], "')\"><i class='fa fa-trash-o' ></i>删除</a>");
                    return ops.join("");
                }
                //设为默认地址
                util.SetDefault = function (id, memberid) {
                    $.post("/Account/SetDefault/", { id: id, memberid: memberid },
                         function (res) {
                             if (res.Status > 0) {
                                 //点击回报设置默认地址，跳回回报
                                 if (res.Status == 2) {
                                     window.location.href = res.Data;
                                     return false;
                                 } else {
                                     $.dialog.tips(res.Message, 1, 'tips.gif', function () {
                                         xjgrid.Reload();
                                     });
                                 }
                             }
                             else {
                                 $.dialog.tips(res.Message);
                             }
                         },
                         "json"
                   );

                };

                //删除
                util.Delete = function (id, name) {
                    $.dialog.confirm('你确定要删除这条记录吗？', function () {
                        $.post(options.DeleteUrl + "/" + id, { id: id },
                                        function (res) {
                                            if (res.Status > 0) {
                                                $.dialog.tips(res.Message, 1, 'tips.gif', function () {
                                                    xjgrid.Reload();
                                                });
                                            }
                                            else {
                                                $.dialog.tips(res.Message);
                                            }
                                        },
                                        "json"
                                  );
                    });

                };
                //编辑
                util.Edit = function (id) {
                    location.href = "/Account/UserAddressEdit" + "/" + id;
                };
                $('#add').click(function () {
                    location.href = "/Account/UserAddressEdit";
                });
            });
        })(window, undefined, jQuery);
        var util = {};
        var options = {
            listUrl: "@Url.Action("UserAddressList", new { MemberId = ViewBag.Mid })",
            DeleteUrl: "@Url.Action("AddrDelete")"
        };
    </script>
}

<div class="RightContrent">
    <div style="margin-left: 50px; margin-right: 50px;">
        <div class="tab-content">
            <div class="line10"></div>
            <div class="line10"></div>
            <div class="tab_title">@ViewBag.Title</div>
            <div class="tab-content">
                <div style="width: 16px; height: 12px; float: left;">
                    <img src="~/Content/Images/leftarraw.png" />
                </div>
            </div>

            <div class="tab-content_border">
                <div class="u-center">
                    @*<input type="hidden" name="ID" id="hidMid" value="@Model.ID" >*@
                    <div class="menu-list" align="right">
                        <input type="button" id="add" name="button" class="btn btn82 btn_save2" value="添加">
                    </div>
                    <div class="line10"></div>
                    <div id="gridlist">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
